package com.hrms.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hrms.entity.Orders;
import com.hrms.mapper.OrdersMapper;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class OrdersServiceImpl extends ServiceImpl<OrdersMapper, Orders> implements OrdersService {
    public List<Map<String, Object>> selectAll() {
        // 返回表orders的所有记录
        return listMaps();
    }

    public boolean checkStatue(Orders orders) {
        // 根据order_id和order_status查询历史订单号状态是否匹配
        QueryWrapper<Orders> wrapper = new QueryWrapper<>();
        wrapper.eq("order_id", orders.getOrder_id())
                .eq("order_status", orders.getOrder_status());
        int count = (int) count(wrapper);

        if(count == 0) return false;
        else return true;
    }

    public boolean updateStatue(Orders orders) {
        // 根据order_id修改order_status
        // true表示修改成功
        QueryWrapper<Orders> wrapper = new QueryWrapper<>();
        wrapper.eq("order_id", orders.getOrder_id());

        return update(orders, wrapper);
    }

    public boolean add(Orders orders) {
        // 在表orders中添加一条记录
        // true表示添加成功
        return save(orders);
    }

    public List<Map<String, Object>> selectbyUser(Orders orders) {
        // 查询表orders的指定列的所有记录
        // order_room_id, order_room_type, order_room_price,
        // order_start_time, order_end_time, order_status
        QueryWrapper<Orders> wrapper = new QueryWrapper<>();
        wrapper.eq("order_user_id", orders.getOrder_user_id())
                .select("order_room_id", "order_stay_name", "order_room_type",
                        "order_room_price", "order_start_time", "order_end_time", "order_status");

        return listMaps(wrapper);
    }

    public List<Map<String, Object>> selectbyEmployee() {
        // 查询表orders的指定列的所有记录
        // order_id、order_room_id、order_customer_name、
        // order_start_time、order_end_time、order_employee_name

        QueryWrapper<Orders> wrapper = new QueryWrapper<>();
        wrapper.select("order_id", "order_room_id", "order_customer_name",
                "order_stay_name", "order_start_time", "order_end_time", "order_employee_name");

        return listMaps(wrapper);
    }

    public boolean delete(Orders orders) {
        // 根据order_id在表orders中删除一条记录
        // true表示删除成功

        QueryWrapper<Orders> wrapper = new QueryWrapper<>();
        wrapper.eq("order_id", orders.getOrder_id());
        return remove(wrapper);
    }
}
